from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
import settings
import models
import cgi
import logging

class ProfileHandler(webapp.RequestHandler):
            
    def get(self):
        template_values = settings.base_template_data(self.request)
        path = settings.template_path('profile')
        self.response.out.write(template.render(path, template_values))
    def post(self):
        user = models.User.get_current_user()
        user.private = bool(cgi.escape(self.request.get('private')))
        lat = cgi.escape(self.request.get('lat'))
        lon = cgi.escape(self.request.get('lon'))
        user.location = db.GeoPt(lat,lon)
        user.put()
        self.redirect('/profile')
        
application = webapp.WSGIApplication(
		[('/profile', ProfileHandler)],
		debug=settings.debug)

def main():
	run_wsgi_app(application)

if __name__=='__main__':
	main()
